import {PathDefault} from '../FileList'

export class Vfx {
  constructor(file, loop = false, path = PathDefault) {
    this.audio = document.createElement("audio");
    this.audio.src = path + file + '.mp3';
    this.audio.loop = loop;
    this.audio.autoplay = false;
    this.fin = false;
    this.audio.onload = this.loaded();
  }

  loaded() {
    // console.log(this.audiourl + '加载完成');
    this.fin = true;
  }

  finished() {
    return this.fin;
  }

  getVfx() {
    if (this.fin) {
      return this.audio;
    } else {
      return null;
    }
  }

  play() {
    this.audio.currentTime = 0;
    this.audio.play();
  }

  pause() {
    this.audio.pause();
  }
}
